
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>你以为你懂InnoDB锁机制 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>你以为你懂InnoDB锁机制 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">InnoDB行级锁具有哪三个关键特性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 细粒度：只锁定需要修改的数据。2. 自动管理：根据事务自动进行加锁和解锁。3. 冲突检测：写锁会阻塞其他的写锁。</div>
          </div>
          <div class="card-source">来源: 一、什么是行级锁？</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在InnoDB中，如何通过SQL语句分别施加共享锁（S锁）和排他锁（X锁）？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">施加共享锁（S锁）使用 `SELECT * FROM table WHERE id=1 LOCK IN SHARE MODE;`。施加排他锁（X锁）使用 `SELECT * FROM table WHERE id=1 FOR UPDATE;`。</div>
          </div>
          <div class="card-source">来源: 二、比Java的synchronized复杂10倍 -> 1. 记录锁（Record Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是间隙锁（Gap Lock），它的主要作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">间隙锁是专门锁定两个现有记录之间空隙的锁。它的主要作用是防止其他事务在这个被锁定的区间内插入新的数据，例如在(3,5)区间加锁后，可以防止插入id=4的记录。</div>
          </div>
          <div class="card-source">来源: 二、比Java的synchronized复杂10倍 -> 2. 间隙锁（Gap Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是临键锁（Next-Key Lock），以及为什么它很重要？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">临键锁是记录锁和间隙锁的组合，它会同时锁住当前记录以及该记录之前的间隙。它很重要，因为它是InnoDB的默认锁模式，并且是许多死锁问题的根源。</div>
          </div>
          <div class="card-source">来源: 二、比Java的synchronized复杂10倍 -> 3. 临键锁（Next-Key Lock）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">根据文档中的锁兼容性表，排他锁（X锁）与其他锁（X锁、S锁、间隙锁）的兼容关系是怎样的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">排他锁（X锁）与X锁、S锁、间隙锁全都不兼容。</div>
          </div>
          <div class="card-source">来源: 三、数据库版的锁</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">死锁的产生需要满足哪四个必要条件？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">死锁产生的四个必要条件是：1. 互斥条件；2. 请求与保持条件；3. 不剥夺条件；4. 循环等待条件。</div>
          </div>
          <div class="card-source">来源: 四、如何解决死锁 -> 死锁产生的四个必要条件：</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在MySQL中，应该使用什么命令来查看最近发生的死锁的详细信息？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该使用 `SHOW ENGINE INNODB STATUS` 命令来查看最新检测到的死锁的详细信息。</div>
          </div>
          <div class="card-source">来源: 四、如何解决死锁</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">为了优化数据库锁性能，在事务控制方面有哪些建议？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了三个建议：1. 尽量使用短事务；2. 避免在事务中执行远程调用；3. 合理设置事务隔离级别。</div>
          </div>
          <div class="card-source">来源: 五、如何优化 -> 2. 事务控制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提到的“隐式转换索引失效”是什么问题？请举例说明。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">这是指在查询条件中，对索引列进行隐式类型转换，从而导致索引无法被使用，最终引发全表扫描。例如，在一个varchar类型的列上使用 `WHERE varchar_col = 123` 进行查询，数据库需要进行类型转换，从而使索引失效。</div>
          </div>
          <div class="card-source">来源: 六、我踩过的五个深坑</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
